/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jmooc.service;

import com.jmooc.dao.ReadCourseDao;
import com.jmooc.entity.Course;
import com.jmooc.entity.ReadCourse;
import com.jmooc.entity.User;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Group
 */
@Stateless
public class ReadCourseService implements Serializable {
     
    @EJB
    private ReadCourseDao readCourseDao;
    
    
    public void create(ReadCourse readCourse) {
        readCourseDao.create(readCourse);
    }
    
    public List<ReadCourse> getAllByUser(User user) {
        return readCourseDao.getAllByUser(user);
    }
    
    public boolean isUserAlreadyReadingACourse(User user, Course course) {
        try {
            ReadCourse rc = readCourseDao.getByUserAndCourse(user, course);
            
            return true;
        } catch (Exception e) {
        }
        
        return false;
    }
}
